package com.cn.ycy.service;

import com.cn.ycy.dao.UserMapper;
import com.cn.ycy.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserMapperServiceImpl {

    @Autowired
    UserMapper userMapper;

    public int insert10() {
        User user = new User();
        user.setUserId(10);
        int insert = userMapper.insert(user);
        return insert;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public int insert11() {
        User user = new User();
        user.setUserId(11);
        return userMapper.insert(user);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public int insert12() {
        User user = new User();
        user.setUserId(12);
        return userMapper.insert(user);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public int insert13() {
        User user = new User();
        user.setUserId(13);
        return userMapper.insert(user);
    }

    @Transactional
    public int rollerbackExp() {
        User user = new User();
        user.setUserId(100);
        int insert = 0;
        insert = userMapper.insert(user);
        insert = userMapper.insert(user);//抛出异常
        return insert;
    }

    public int insert() {
        User user = new User();
        int insert;
        insert = userMapper.insert(user);
        return insert;
    }

}
